package com.cbs.android.component.binaryutils.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cbs.android.component.binaryutils.BinaryUtils;
import com.cbs.android.component.log.L;

import java.nio.charset.Charset;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void gzip(View view) {
        String str = "福建省代发价当时覅就发群里玩分解放前欧违法金饭碗非非完全";
        byte[] bytes1 = str.getBytes(Charset.forName("utf-8"));
        byte[] bytes2 = BinaryUtils.gzip(bytes1);
        byte[] bytes3 = BinaryUtils.ungzip(bytes2);
        String str2 = new String(bytes3, Charset.forName("utf-8"));
        L.e(TAG, String.format("str: %s\nbytes1: %d\nbytes2: %d\nbytes3: %d\nstr2: %s", str, bytes1.length, bytes2.length, bytes3.length, str2));
    }

    public void base64(View view) {
        String str = "福建省代发价当时覅就发群里玩分解放前欧违法金饭碗非非完全";
        byte[] bytes1 = str.getBytes(Charset.forName("utf-8"));
        byte[] bytes2 = BinaryUtils.base64Encode(bytes1);
        byte[] bytes3 = BinaryUtils.base64Decode(bytes2);
        String str2 = new String(bytes3, Charset.forName("utf-8"));
        L.e(TAG, String.format("str: %s\nbase64: %s\nstr2: %s", str, new String(bytes2), str2));
    }

    public void md5(View view) {
        String str = "福建省代发价当时覅就发群里玩分解放前欧违法金饭碗非非完全";
        byte[] bytes1 = str.getBytes(Charset.forName("utf-8"));
        String str2 = BinaryUtils.md5(bytes1);
        L.e(TAG, String.format("str: %s\nmd5: %s", str, str2));
    }
}
